package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.ResourceDAO;
import guda.house.dal.dataobject.ResourceDO;
import guda.grape.autogen.common.page.BaseQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResourceDAOImpl extends BaseDAO implements ResourceDAO {

    @Override
	public Long insert(ResourceDO resource) {
	      try {
                return (Long) getSqlMapperW().insert("resource.insert",resource);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public ResourceDO getResourceById(Long resourceId) {
	    return (ResourceDO)getSqlMapClientTemplate().queryForObject("resource.getResourceById", resourceId);
	}

    @Override
	public boolean delResourceById(Long resourceId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("resource.delResourceById",resourceId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<ResourceDO> getResourceByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("resource.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long resourceId) {
	    try {
            getSqlMapperW().update("resource.cleanAutoIncrement",resourceId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<ResourceDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("resource.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("resource.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(ResourceDO resource) {
        try {
            getSqlMapperW().update("resource.updateByIdSelective",resource);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

